package com.zx.map.dao.impl;

import com.zx.map.dao.ShareProfitLogDao;
import com.zx.map.dao.mapper.ShareProfitLogMapper;
import com.zx.map.dao.model.AgentInfo;
import com.zx.map.dao.model.ShareProfitLog;
import com.zx.map.dao.model.ShareProfitLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA. User: Administrator Date: 14-3-1 Time: 上午10:54 To
 * change this template use File | Settings | File Templates.
 */
@Component("shareProfitLogDao")
public class ShareProfitLogImpl implements ShareProfitLogDao {

	@Autowired
	private ShareProfitLogMapper mapper;

	/**
	 * 新增
	 */
	public String add(ShareProfitLog shareProfitLog) throws DataAccessException {
		int column = mapper.insert(shareProfitLog);
		if (column != 1) {
			throw new RuntimeException("");
		}
		return shareProfitLog.getCustId();
	}

	/**
	 * 修改
	 * 
	 * @param shareProfitLog
	 * @return
	 * @throws org.springframework.dao.DataAccessException
	 * 
	 */
	public String update(ShareProfitLog shareProfitLog)
			throws DataAccessException {
		int column = mapper.updateByPrimaryKeySelective(shareProfitLog);
		if (column != 1) {
			throw new RuntimeException("");
		}
		return shareProfitLog.getCustId();
	}

	/**
	 * 删除
	 */
	public void delete(ShareProfitLog shareProfitLog)
			throws DataAccessException {
		int column = mapper.deleteByPrimaryKey(shareProfitLog.getCustId());
		if (column != 1) {
			throw new RuntimeException("");
		}
	}

	/**
     *
     */
	public List<ShareProfitLog> getListByExample(ShareProfitLogExample example)
			throws DataAccessException {
		return mapper.selectByExample(example);
	}

	/**
    *
    */
	public int countListByExample(ShareProfitLogExample example)
			throws DataAccessException {
		return mapper.countByExample(example);
	}

	/**
	 * 根据筛选的记录 更新某个字段
	 */
	public void updateByExample(ShareProfitLog shareProfitLog,
			ShareProfitLogExample example) throws DataAccessException {
		mapper.updateByExampleSelective(shareProfitLog, example);
	}

	/**
	 * 分页查找
	 */
	public List<ShareProfitLog> getPageByExample(int pageSize, int pageBegin,
			ShareProfitLogExample example) throws DataAccessException {
		return mapper.getPageByModel(pageSize, pageBegin, example);
	}

	@Override
	public List<ShareProfitLog> queryShareProfitLog(AgentInfo agentInfo, ShareProfitLog shareProfitLogModel, int beginIndex) {
		return mapper.queryShareProfitLog(agentInfo, shareProfitLogModel,beginIndex);
	}

	@Override
	public int queryCountShareProfitLog(AgentInfo agentInfo, ShareProfitLog shareProfitLogModel) {
		return mapper.queryCountShareProfitLog(agentInfo, shareProfitLogModel);
	}
	/**
	 *代理商收益 分享收益汇总
	 */
	@Override
	public double countSprofitBal(ShareProfitLogExample example) {
		return mapper.countSprofitBal(example);
	}
	/**
	 *代理商收益 可用余额汇总
	 */
	@Override
	public double countSprofitAvlAmt(ShareProfitLogExample example) {
		return mapper.countSprofitAvlAmt(example);
	}
}
